import { CheckBox, ComboBox, ScrollView, Slider } from "std-widgets.slint";
import { ActiveTab } from "common.slint";
import { Settings } from "settings.slint";
import { GuiState } from "gui_state.slint";
import { TextComponent } from "settings_list.slint";
import { Translations } from "translations.slint";

component ComboBoxWrapper inherits HorizontalLayout {
    in-out property <string> text;
    in-out property <[string]> model;
    in-out property <int> current_index;
    in-out property <string> current_value;
    spacing: 5px;
    Text {
        text <=> root.text;
        vertical_alignment: TextVerticalAlignment.center;
    }

    ComboBox {
        model: root.model;
        current_index <=> root.current_index;
        current_value <=> root.current_value;
    }
}

component CheckBoxWrapper inherits CheckBox { }

component SubsettingsHeader inherits Text {
    text: Translations.subsettings_text;
    font-size: 15px;
    height: 30px;
}

component SliderWrapper inherits HorizontalLayout {
    in-out property <float> maximum;
    in-out property <float> minimum: 0;
    in-out property <float> value;
    in-out property <string> text;
    in-out property <string> end_text;
    in-out property <length> end_text_size;
    spacing: 5px;
    Text {
        text: root.text;
    }

    Slider {
        min-width: 30px;
        minimum <=> root.minimum;
        maximum <=> root.maximum;
        value <=> root.value;
    }

    Text {
        text: root.end_text;
        width: root.end_text_size;
    }
}

export component ToolSettings {
    ScrollView {
        VerticalLayout {
            visible: GuiState.active_tab == ActiveTab.SimilarImages;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }

            ComboBoxWrapper {
                text: Translations.subsettings_images_hash_size_text;
                model: Settings.similar_images_sub_available_hash_size;
                current_index <=> Settings.similar_images_sub_hash_size_index;
                current_value <=> Settings.similar_images_sub_hash_size_value;
            }

            ComboBoxWrapper {
                text: Translations.subsettings_images_resize_algorithm_text;
                model: Settings.similar_images_sub_available_resize_algorithm;
                current_index <=> Settings.similar_images_sub_resize_algorithm_index;
                current_value <=> Settings.similar_images_sub_resize_algorithm_value;
            }

            ComboBoxWrapper {
                text: Translations.subsettings_images_duplicates_hash_type_text;
                model: Settings.similar_images_sub_available_hash_type;
                current_index <=> Settings.similar_images_sub_hash_alg_index;
                current_value <=> Settings.similar_images_sub_hash_alg_value;
            }

            Rectangle {
                height: 0px;
            }

            CheckBoxWrapper {
                text: Translations.subsettings_images_ignore_same_size_text;
                checked <=> Settings.similar_images_sub_ignore_same_size;
            }

            Rectangle {
                height: 4px;
            }

            SliderWrapper {
                text: Translations.subsettings_images_max_difference_text;
                end_text: "(" + round(Settings.similar_images_sub_current_similarity) + "/" + round(Settings.similar_images_sub_max_similarity) + ")";
                end_text_size: 40px;
                maximum <=> Settings.similar_images_sub_max_similarity;
                value <=> Settings.similar_images_sub_current_similarity;
            }

            Rectangle { }
        }

        VerticalLayout {
            visible: GuiState.active_tab == ActiveTab.DuplicateFiles;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }

            ComboBoxWrapper {
                text: Translations.subsettings_duplicates_check_method_text;
                model: Settings.duplicates_sub_check_method;
                current_index <=> Settings.duplicates_sub_check_method_index;
                current_value <=> Settings.duplicates_sub_check_method_value;
            }

            ComboBoxWrapper {
                text: Translations.subsettings_images_duplicates_hash_type_text;
                model: Settings.duplicates_sub_available_hash_type;
                current_index <=> Settings.duplicates_sub_available_hash_type_index;
                current_value <=> Settings.duplicates_sub_available_hash_type_value;
            }

            CheckBoxWrapper {
                text: Translations.subsettings_duplicates_name_case_sensitive_text;
                checked <=> Settings.duplicates_sub_name_case_sensitive;
                height: 25px;
            }

            Rectangle { }
        }

        VerticalLayout {
            visible: GuiState.active_tab == ActiveTab.BigFiles;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }

            ComboBoxWrapper {
                text: Translations.subsettings_biggest_files_sub_method_text;
                model: Settings.biggest_files_sub_method;
                current_index <=> Settings.biggest_files_sub_method_index;
                current_value <=> Settings.biggest_files_sub_method_value;
            }

            TextComponent {
                name: Translations.subsettings_biggest_files_sub_number_of_files_text;
                model <=> Settings.biggest_files_sub_number_of_files;
            }

            Rectangle { }
        }

        VerticalLayout {
            visible: GuiState.active_tab == ActiveTab.SimilarVideos;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }
            CheckBoxWrapper {
                text: Translations.subsettings_videos_ignore_same_size_text;
                checked <=> Settings.similar_videos_sub_ignore_same_size;
            }

            Rectangle {
                height: 0px;
            }

            ComboBoxWrapper {
                text: Translations.subsettings_videos_crop_detect_text;
                model: Settings.similar_videos_crop_detect;
                current_index <=> Settings.similar_videos_crop_detect_index;
                current_value <=> Settings.similar_videos_crop_detect_value;
            }

            Rectangle {
                height: 0px;
            }

            SliderWrapper {
                text: Translations.subsettings_videos_max_difference_text;
                end_text: "(" + round(Settings.similar_videos_sub_current_similarity) + "/" + round(Settings.similar_videos_sub_max_similarity) + ")";
                end_text_size: 40px;
                maximum <=> Settings.similar_videos_sub_max_similarity;
                value <=> Settings.similar_videos_sub_current_similarity;
            }

            SliderWrapper {
                text: Translations.subsettings_videos_skip_forward_amount_text;
                end_text: "(" + round(Settings.similar_videos_skip_forward_amount) + "/" + round(Settings.similar_videos_skip_forward_amount_max) + ")";
                end_text_size: 55px;
                maximum <=> Settings.similar_videos_skip_forward_amount_max;
                minimum <=> Settings.similar_videos_skip_forward_amount_min;
                value <=> Settings.similar_videos_skip_forward_amount;
            }

            SliderWrapper {
                text: Translations.subsettings_videos_vid_hash_duration_text;
                end_text: "(" + round(Settings.similar_videos_vid_hash_duration) + "/" + round(Settings.similar_videos_vid_hash_duration_max) + ")";
                end_text_size: 40px;
                maximum <=> Settings.similar_videos_vid_hash_duration_max;
                minimum <=> Settings.similar_videos_vid_hash_duration_min;
                value <=> Settings.similar_videos_vid_hash_duration;
            }


            Rectangle { }
        }

        VerticalLayout {
            visible: GuiState.active_tab == ActiveTab.SimilarMusic;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }

            ComboBoxWrapper {
                text: Translations.subsettings_music_audio_check_type_text;
                model: Settings.similar_music_sub_audio_check_type;
                current_index <=> Settings.similar_music_sub_audio_check_type_index;
                current_value <=> Settings.similar_music_sub_audio_check_type_value;
            }
            if Settings.similar_music_sub_audio_check_type_index == 0: VerticalLayout {
                spacing: 5px;
                CheckBoxWrapper {
                    text: Translations.subsettings_music_approximate_comparison_text;
                    checked <=> Settings.similar_music_sub_approximate_comparison;
                    height: 40px;
                }

                Text {
                    text: Translations.subsettings_music_compared_tags_text + ":";
                    font-size: 12px;
                    height: 20px;
                }

                CheckBoxWrapper {
                    text: Translations.subsettings_music_title_text;
                    checked <=> Settings.similar_music_sub_title;
                }

                CheckBoxWrapper {
                    text: Translations.subsettings_music_artist_text;
                    checked <=> Settings.similar_music_sub_artist;
                }

                CheckBoxWrapper {
                    text: Translations.subsettings_music_bitrate_text;
                    checked <=> Settings.similar_music_sub_bitrate;
                }

                CheckBoxWrapper {
                    text: Translations.subsettings_music_genre_text;
                    checked <=> Settings.similar_music_sub_genre;
                }

                CheckBoxWrapper {
                    text: Translations.subsettings_music_year_text;
                    checked <=> Settings.similar_music_sub_year;
                }

                CheckBoxWrapper {
                    text: Translations.subsettings_music_length_text;
                    checked <=> Settings.similar_music_sub_length;
                }

                Rectangle {}
            }
            if Settings.similar_music_sub_audio_check_type_index == 1: VerticalLayout {
                spacing: 5px;

                CheckBoxWrapper {
                    text: Translations.subsettings_music_compare_fingerprints_only_with_similar_titles_text;
                    checked <=> Settings.similar_music_compare_fingerprints_only_with_similar_titles;
                    height: 40px;
                }
                SliderWrapper {
                    text: Translations.subsettings_music_max_difference_text;
                    end_text: "(" + round(Settings.similar_music_sub_maximum_difference_value) + "/" + round(Settings.similar_music_sub_maximum_difference_max) + ")";
                    end_text_size: 40px;
                    maximum <=> Settings.similar_music_sub_maximum_difference_max;
                    value <=> Settings.similar_music_sub_maximum_difference_value;
                }

                SliderWrapper {
                    text: Translations.subsettings_music_minimal_fragment_duration_text;
                    end_text: round(Settings.similar_music_sub_minimal_fragment_duration_value);
                    end_text_size: 40px;
                    maximum <=> Settings.similar_music_sub_minimal_fragment_duration_max;
                    value <=> Settings.similar_music_sub_minimal_fragment_duration_value;
                }
            }
            Rectangle { }
        }

        VerticalLayout {
            visible: GuiState.active_tab == ActiveTab.BrokenFiles;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }

            Text {
                text: Translations.subsettings_broken_files_type_text;
                font-size: 12px;
                height: 25px;
            }

            CheckBoxWrapper {
                text: Translations.subsettings_broken_files_audio_text;
                checked <=> Settings.broken_files_sub_audio;
            }

            CheckBoxWrapper {
                text: Translations.subsettings_broken_files_pdf_text;
                checked <=> Settings.broken_files_sub_pdf;
            }

            CheckBoxWrapper {
                text: Translations.subsettings_broken_files_archive_text;
                checked <=> Settings.broken_files_sub_archive;
            }

            CheckBoxWrapper {
                text: Translations.subsettings_broken_files_image_text;
                checked <=> Settings.broken_files_sub_image;
            }

            Rectangle { }
        }
    }
}
